Algolia doesn’t directly search your data sources. Instead, you upload the parts of your data that are relevant for search to Algolia. Algolia stores this data in an index: a data structure optimized for fast search.

Required credentials

To send data to Algolia, you need an Application ID and a valid API key (with addObjects permission). You can find them in the API Keys section of Algolia’s dashboard.

Application ID

Your Application ID is what Algolia uses to identify your app, where all your indices live.

API key

API keys control access to Algolia’s API and determine what you’re allowed to do, such as searching an index, or adding new records. For better security, create specific API keys with minimal permissions for indexing tasks, which you should only use in server-side code. Keep your indexing API keys secret. Only use the Admin API key to create other API keys. Don’t use the Admin API key in your apps.

Set up the API client

First, you need to install and set up your API client. For installation instructions, go to the API client documentation for your programming language: After installing the API client, you can initialize it and connect to Algolia:
SearchClient client = new SearchClient("YourApplicationID", "YourWriteAPIKey");
SearchIndex index = client.InitIndex("your_index_name");

Fetch your data

Before sending anything to Algolia, you need to retrieve your data. You can do this in several ways, depending on the nature of your app. Here are potential examples:

From a database

IEnumerable<Actor> FetchDataFromDataBase()
{
    // Fetch data from your database
}

var actors = FetchDataFromDataBase();

From a file

You can use this actors dataset to test this out.
using System.Collections.Generic;
using System.IO;
using Algolia.Search.Clients;
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;

public class Actor
{
    public string Name { get; set; }
    public string ObjectID { get; set; }
    public int Rating { get; set; }
    public string ImagePath { get; set; }
    public string AlternativePath { get; set; }
}

public class AlgoliaActorsIndexer
{
    private SearchClient client;
    private SearchIndex index;

    public AlgoliaActorsIndexer(string appId, string apiKey, string indexName)
    {
        client = new SearchClient(appId, apiKey);
        index = client.InitIndex(indexName);
    }

    public void IndexActorsFromFile(string filePath)
    {
        var settings = new JsonSerializerSettings
        {
            ContractResolver = new DefaultContractResolver
            {
                NamingStrategy = new CamelCaseNamingStrategy()
            }
        };

        IEnumerable<Actor> actors = JsonConvert.DeserializeObject<IEnumerable<Actor>>(
            File.ReadAllText(filePath),
            settings
        );
        index.SaveObjects(actors);
    }
}

// Usage
public class Program
{
    public static void Main(string[] args)
    {
        AlgoliaActorsIndexer indexer = new AlgoliaActorsIndexer(
            "YourApplicationID",
            "YourWriteAPIKey",
            "actors"
        );
        indexer.IndexActorsFromFile("actors.json");
    }
}

From the source code directly

Only use this method for exploration purposes or if you have a small amount of data.
using System.Collections.Generic;

public class Actor
{
    public string Name { get; set; }
}

public class Program
{
    public static void Main()
    {
        IEnumerable<Actor> records = new List<Actor>
        {
            new Actor { Name = "Tom Cruise" },
            new Actor { Name = "Scarlett Johansson" }
        };
    }
}

Send the data to Algolia

Once the records are ready, you can push them to Algolia using the saveObjects method.
index.SaveObjects(records, autoGenerateObjectId: true);

Send your data in batches

For performance reasons, you should send several records at once instead of one by one. If you have many records to index, you should send them in batches. Once you’re done, you can configure relevance settings.